package model.doe;

public abstract class Fresnel extends AbstractDoe{
	static double d_max = 0, d = 0, f = 0, angle, Cos;

	static double d_max2 = 0, d2 = 0, f2 = 0;
	static double d_max3 = 0, d3 = 0, f3 = 0;
	static int sign__ = 0;

	private double t_max;

	private double g;

	private double t;

	private double a_min;

	private double a_max;

	// F(r)=(2*Pi/wl)*(Fmax-sqrt(fokus**2+r**2)

	// Fmax=sqrt(fokus**2+Rmax**2)

	// F(u,v)=(2*Pi/wl)*(

	// Fmax_u-sqrt(fokus_u**2+u**2)+

	// Fmax_v-sqrt(fokus_v**2+v**2)

	// ) , £€¥

	// Fmax_u=sqrt(fokus_u**2+u_max**2),

	// Fmax_v=sqrt(fokus_v**2+v_max**2)

	public Fresnel() {

	}

	double fr__(double t, double t_max, double g, double r) {

		double a;
		double p = t * (t_max - Math.sqrt(g * g + r * r));
		System.out.println(p);
		if (p < 0){
			p = 0;
		}
		if (p > (a = t * t_max)){
			p = a;
		}
		return p;

	}

	void fresnelInit(double rad, double fokus, double wl) {

		t_max = Math.sqrt(fokus * fokus + rad * rad);
		System.out.println("t_max "+t_max);
		g = fokus;
		System.out.println("g "+g);
		t = 2 * Math.PI * 1000 / wl;
		System.out.println("t "+t);
		a_min = fr__(t, t_max, g, rad);
		a_max = fr__(t, t_max, g, 0);
		maximumValue = a_max;
		minValue = a_min;
	}
	
	private void fresnel2Init(double rad, double fokus, double wl) {
		
		t_max = Math.sqrt(fokus * fokus + rad * rad);
		System.out.println("t_max "+t_max);
		g = fokus;
		System.out.println("g "+g);
		t = 2 * Math.PI * 1000 / wl;
		System.out.println("t "+t);
		a_min = fr__(t, t_max, g, rad);
		a_max = fr__(t, t_max, g, 0);
		maximumValue += a_max;
		minValue += a_min;
	}

	String fresnel_com() {
		return "Fresnel lens";
	}

	// ****************************************************

	void fresnel_init(double rad, double fok, double wl) {

		fresnelInit(rad, fok, wl);
	}

	double fresnel(double r) {
		return fr__(t, t_max, g, r);
	}

	// ****************************************************

	void fresnelA_init(double rad, double fok, double wl, double cos) {
		Cos = cos;
		fresnelInit(rad, fok, wl);

	}

	double fresnelA(double u, double v) {

		double r;
		u = Cos * u;
		r = Math.sqrt(u * u + v * v);
		return fr__(t, t_max, g, r);
	}

	// ****************************************************

	void fresnel2_init(double rad, double fok, double wl) {

		fresnel2Init(rad, fok, wl);

	}



	double fresnel2(double r) {
		return fr__(d2, d_max2, f2, r);
	}

	// ****************************************************

	void fresnel3_init(double rad, double fok, double wl, double a_max,
			double a_min, int s) {

		fresnelInit(rad, fok, wl);

		sign__ = s;

	}

	double fresnel3(double u, double v) {

		if (sign__ == 0)
			return fr__(d3, d_max3, f3, u);

		else
			return fr__(d3, d_max3, f3, v);

	}

	// ****************************************************

	void fresnel_annular() {

		String name = "   DOE : Annular Lens   ";

		String Par[] = {

		"Aperture   Radius  :",

		"Angle              :",

		"Focal      Length  :",

		"WaveLength (micron):",

		"Discretization Step:"

		};

		String Def[] = {

		"    2.0          ",

		"    2.0          ",

		"    25.0         ",

		"    10.6          ",

		"     .04         "

		};

		double rad, f, wl, step;

		

	}

	// ****************************************************

	void fresnel_cylindrical() {

		String name = "   DOE : Cylindrical Lens   ";

		String Par[] = { "Height             :",

		"Width              :",

		"Focal   Length     :",

		"WaveLength (micron):",

		"Discretization Step:"

		};

		String Def[] = { "2.                       ",

		"2.                       ",

		"25.                      ",

		"10.6                     ",

		".04                      " };

		double f, wl;

	}

	public void fresnel_crossed_init(double DoeHeight, double fh, double wl, double DoeWidth, double fw, double wl2) {
		fresnel_init (DoeHeight, fh, wl);
		fresnel2_init(DoeWidth, fw, wl);		
	}
}
